package ar.com.spsolutions.splibrary.notifiers;

import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;

import ar.com.spsolutions.splibrary.user.User;

public class MockNotifier implements INotifier {
	private static final long serialVersionUID = -1610589421126518125L;

	protected static final Logger LOG = Logger.getLogger(MockNotifier.class
			.getCanonicalName());

	private String message;

	private String subject;
	private boolean dummy;
	private String debug;
	private String user;
	private String password;
	private String transport;

	private String host;
	private String tls;
	private String port;
	private String authorization;

	private transient Set<User> recipients;

	@Override
	public void setMessage(final String mailMessage) {
		this.message = mailMessage;
	}

	public String getMessage() {
		return this.message;
	}

	@Override
	public void setSubject(final String subject) {
		this.subject = subject;
	}

	public String getSubject() {
		return this.subject;
	}

	@Override
	public void setRecipients(final Set<User> users) {
		this.recipients = users;
	}

	public Set<User> getRecipients() {
		return this.recipients;
	}

	@Override
	public void sendNotification() {
		final StringBuffer buffer = new StringBuffer(100);
		buffer.append("####################EMAIL#####################\n");
		buffer.append(this.getRecipentsString());
		buffer.append('\n');
		buffer.append(this.getSubject());
		buffer.append('\n');
		buffer.append(this.getMessage());
		buffer.append("\n##############################################");
		MockNotifier.LOG.info(buffer.toString());
	}

	private String getRecipentsString() {
		final StringBuffer buffer = new StringBuffer(19);
		buffer.append("RECIPIENTS:[");
		for (final User recipient : this.getRecipients()) {
			buffer.append('<');
			buffer.append(recipient.getName());
			buffer.append("> : ");
			buffer.append(recipient.getEmail());
			buffer.append("; ");
		}
		buffer.setLength(buffer.length() - 2);
		buffer.append("].");
		return buffer.toString();
	}

	@Override
	public void setRecipient(final User aUser) {
		final Set<User> tempReceivers = new HashSet<User>();
		tempReceivers.add(aUser);
		this.setRecipients(tempReceivers);
	}

	public String getUser() {
		return this.user;
	}

	public void setUser(final String user) {
		this.user = user;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(final String password) {
		this.password = password;
	}

	public String getTransport() {
		return this.transport;
	}

	public void setTransport(final String transport) {
		this.transport = transport;
	}

	public String getHost() {
		return this.host;
	}

	public void setHost(final String host) {
		this.host = host;
	}

	public boolean isDummy() {
		return this.dummy;
	}

	public void setDummy(final boolean dummy) {
		this.dummy = dummy;
	}

	public String getDebug() {
		return this.debug;
	}

	public void setDebug(final String debug) {
		this.debug = debug;
	}

	public String getTls() {
		return this.tls;
	}

	public void setTls(final String tls) {
		this.tls = tls;
	}

	public String getPort() {
		return this.port;
	}

	public void setPort(final String port) {
		this.port = port;
	}

	public String getAuthorization() {
		return this.authorization;
	}

	public void setAuthorization(final String authorization) {
		this.authorization = authorization;
	}

}
